<template>
	<view class="page">
	<view class="wd710">
		<view class="title_h3_reload">
			<text>出入库管理</text>
			<uni-icons type="refreshempty" size="20" @click="refreshMenu"></uni-icons>
		</view>
		<uni-grid class="gaid-box" :column="3" :showBorder="false">
			<uni-grid-item v-for="item in outInlist" :key="item.sTypeCode">
				<view class="grid-item" @click="gosType(item)">
					<image :src="'../static/icon/' + item.iImageIndex" class="menu-img"></image>
					<text>{{ item.sTypeName }}</text>
				</view>
			</uni-grid-item>
		</uni-grid>
		<view class="title_h3_reload">
			<text>查询管理</text>
		</view>
		<uni-grid class="gaid-box" :column="3" :showBorder="false">
			<uni-grid-item v-for="item in findList" :key="item.sTypeCode">
				<view class="grid-item" @click="gosList(item)">
					<image :src="'../static/icon/' + item.iImageIndex " class="menu-img"></image>
					<text>{{ item.sTypeName }}</text>
				</view>
			</uni-grid-item>
		</uni-grid>
		<text class="title_h3_reload">外协管理</text>
		<uni-grid :column="3" :showBorder="false">
			<uni-grid-item>
				<view class="grid-item" @click="goReport">
					<image src="../static/icon/b-icon-18.png" class="menu-img"></image>
					<text>报工登记</text>
				</view>
			</uni-grid-item>
			<uni-grid-item>
				<view class="grid-item" @click="goCut">
					<image src="../static/icon/b-icon-19.png" class="menu-img"></image>
					<text>报工</text>
				</view>
			</uni-grid-item>
		</uni-grid>
	</view>
	</view>
</template>

<script>
	import { filter } from "lodash";
	import fabricService from "@/api/auth/fabricService";
	export default {
		data() {
			return {
				outInlist: [],
				findList: [],
			}
		},
		created() {
			this.init();
		},
		methods: {
			async init() {
				const menuList = uni.getStorageSync('menu');
				const scanList = filter(menuList, function(o) { return o.sType === "scan" });
				const findList = filter(menuList, function(o) { return o.sType === "find" });
				this.outInlist = scanList;
				this.findList = findList;
			},
			goReport() {
				uni.navigateTo({
					url: "/pages/subB/reportWork/list"
				});
			},
			goCut() {
				uni.navigateTo({
					url: "/pages/subB/reportWork/cutpackage"
				});
			},
			gosType(item) {
				uni.navigateTo({
					url: "/pages/subB/fabric/index",
					success: (res) => {
						res.eventChannel.emit('sendData', item);
					}
				});
			},
			gosList(item) {
				uni.navigateTo({
					url: "/pages/subB/fabric/list",
					success: (res) => {
						res.eventChannel.emit('sendData', item);
					}
				});
			},
			refreshMenu() {
				uni.showModal({
					title: '刷新菜单',
					content: '是否重新加载菜单',
					success: (res) => {
						if (res.confirm) {
							fabricService.getMenu().then(res => {
								const menuList = res;
								const scanList = filter(menuList, function(o) { return o.sType === "scan" });
								const findList = filter(menuList, function(o) { return o.sType === "find" });
								this.outInlist = scanList;
								this.findList = findList;
								uni.showToast({
									title: "刷新成功",
									duration: 1000,
									icon: "success"
								});
							});
						}
					}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
.page {
	// padding-top: 20rpx;
}
.title_h3_reload {
	width: 710rpx;
	margin: 20rpx auto;
	display: flex;
	justify-content: space-between;
	font-size: 32rpx;
	font-weight: bold;
}
.swiper {
	width: 710rpx;
	background-color: #0081ff;
	margin: 0 auto;
	border-radius: 8rpx;
	.swiper-item {
		width: 100%;
		height: 100%;
		image {
			width: 100%;
			height: 100%;
		}
	}
}
.wd710 {
	width: 710rpx;
	margin: 0 auto;
}
.gaid-box {
	min-height: 244rpx;
}

.menu-img {
	width: 140rpx;
	height: 140rpx;
}

.grid-item {
	 // box-shadow: 0 1px 4px #f9f9f9, 1px 1px 40px rgba(0,0,0,.06);
	 width: 90%;
	 height: 90%;
	 margin: auto;
	 display: flex;
	 flex-direction: column;
	 justify-content: center;
	 align-items: center;
	 font-size: 28rpx;
	 text {
		 margin-top: 10rpx;
	 }
}
</style>
